123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- <?php
- namespace app\admin\controller\order;
- use app\admin\controller\notify\RechargeController;
- use app\controller\Curd;
- use app\model\Goods;
- use app\model\GoodsSku;
- use app\model\Order;
- use app\model\OrderSheet;
- use app\model\PayDetail;
- use support\Db;
- use support\exception\BusinessException;
- use support\Request;
- use support\Response;
- class PayDetailController extends Curd
- {
- public function __construct()
- {
- $this->model = new PayDetail();
- }
- public function select(Request $request): Response
- {
- [$where, $format, $limit, $field, $order] = $this->selectInput($request);
- $order = $request->get('order', 'desc');
- $field = $field ?? 'pay_addtimes';
- // $where['pay_status'] = 'SUCCESS';
- if ($where['pay_category'] == 'OTHER') {
- $where['pay_status'] = 'SUCCESS';
- $where['pay_category'] = ['<>', 'RECHARGE'];
- }
- $query = $this->doSelect($where, $field, $order);
- return $this->doFormat($query, $format, $limit);
- }
- protected function doSelect(array $where, string $field = null, string $order = 'desc')
- {
- $model = $this->model->with(['member', 'cert']);
- foreach ($where as $column => $value) {
- if (is_array($value)) {
- if ($value[0] === 'like' || $value[0] === 'not like') {
- $model = $model->where($column, $value[0], "%$value[1]%");
- } elseif (in_array($value[0], ['>', '=', '<', '<>'])) {
- $model = $model->where($column, $value[0], $value[1]);
- } elseif ($value[0] == 'in' && !empty($value[1])) {
- $valArr = $value[1];
- if (is_string($value[1])) {
- $valArr = explode(",", trim($value[1]));
- }
- $model = $model->whereIn($column, $valArr);
- } elseif ($value[0] == 'not in' && !empty($value[1])) {
- $valArr = $value[1];
- if (is_string($value[1])) {
- $valArr = explode(",", trim($value[1]));
- }
- $model = $model->whereNotIn($column, $valArr);
- } elseif ($value[0] == 'null') {
- $model = $model->whereNull($column);
- } elseif ($value[0] == 'not null') {
- $model = $model->whereNotNull($column);
- } elseif ($value[0] !== '' || $value[1] !== '') {
- $model = $model->whereBetween($column, $value);
- }
- } else {
- $model = $model->where($column, $value);
- }
- }
- if ($field) {
- $model = $model->orderBy($field, $order);
- }
- return $model;
- }
- /**
- * @Desc 产品订单
- * @Author Gorden
- * @Date 2024/6/5 10:10
- *
- * @param Request $request
- * @return Response
- */
- public function goodsOrder(Request $request)
- {
- $orderId = $request->get('order_id', '');
- if (!$orderId) {
- return json_fail('参数异常');
- }
- $orderSheet = OrderSheet::with([
- 'order' => function ($query) {
- $query->select('order_id', 'order_amount_total', 'order_amount_pay', 'order_is_complete', 'order_category', 'order_status_system', 'order_status_payment', 'order_status_storage', 'order_addtimes');
- },
- 'goods' => function ($query) {
- $query->select('goods_id', 'goods_name', 'goods_status', 'goods_market_price', 'goods_sales_price', 'goods_addtimes');
- },
- 'sku' => function ($query) {
- $query->select('goods_sku_id', 'goods_sku_specs_json', 'goods_sku_market_price', 'goods_sku_sales_price');
- }
- ])->where('join_sheet_order_id', $orderId)
- ->get()
- ->toArray();
- return json_success('', $orderSheet);
- }
- public function insertRecharge(Request $request): Response
- {
- if ($this->validate && !$this->validateClass->scene('add')->check($request->post())) {
- return json_fail($this->validateClass->getError());
- }
- $password = $request->post('recharge_password','');
- if(!$password || $password != '123456'){
- return json_fail('充值密码错误');
- }
- try {
- Db::beginTransaction();
- $data = $this->insertRechargeInput($request);
- $payDetailId = $this->doInsert($data);
- (new RechargeController)->disposePaySuccess($payDetailId);
- Db::commit();
- } catch (BusinessException $customException) {
- Db::rollBack();
- return json_fail($customException->getMessage());
- } catch (\Exception $e) {
- Db::rollBack();
- dump($e->getMessage());
- return json_fail('数据写入失败11');
- }
- return json_success('success');
- }
- /**
- * @Desc
- * @Author Gorden
- * @Date 2024/6/5 13:39
- *
- * @param Request $request
- * @return array
- * @throws BusinessException
- */
- protected function insertRechargeInput(Request $request): array
- {
- $params = $request->post();
- $data = $this->inputFilter($params);
- $goods = Goods::find($params['goods_id']);
- $extendJson = [];
- if (!$params['is_custom']) {
- try {
- Db::beginTransaction();
- $data['pay_amount'] = $goods->goods_sales_price;
- // $orderId = "OD" . date("YmdHis") . random_string(6, 'up');
- // $orderGroupId = "OD" . date("YmdHis") . random_string(6, 'up');
- // $orderData = [
- // 'order_id' => $orderId,
- // 'order_groupby' => $orderGroupId,
- // 'join_order_member_id' => $data['join_pay_member_id'],
- // 'order_name' => date('Y-m-d H:i:s') . '-订单',
- // 'order_amount_total' => $data['pay_amount'],
- // 'order_amount_pay' => $data['pay_amount'],
- // 'order_amount_json' => '{"tax": 0, "freight": 0}',
- // 'order_status_payment' => 'SUCCESS',
- // 'order_category' => 'NORMAL',
- // 'order_status_system' => 'WAITING',
- // 'order_status_storage' => 'PENDING',
- // 'order_addtimes' => time()
- // ];
- // $sku = GoodsSku::where('join_sku_goods_id', $params['goods_id'])->first();
- // dump($sku);
- // Order::insert($orderData);
- // $orderSheetData = [
- // 'join_sheet_member_id' => $data['join_pay_member_id'],
- // 'join_sheet_order_id' => $orderId,
- // 'join_sheet_goods_id' => $params['goods_id'],
- // 'join_sheet_goods_sku_id' => $sku ? $sku->goods_sku_id : 0,
- // 'order_sheet_status' => 'PAYING',
- // 'order_sheet_category' => 'NORMAL',
- // 'order_sheet_num' => 1,
- // 'order_sheet_price' => $data['pay_amount'],
- // 'order_sheet_amount' => $data['pay_amount'],
- // 'order_sheet_pay' => $data['pay_amount'],
- // 'order_sheet_addtimes' => time()
- // ];
- // OrderSheet::insert($orderSheetData);
- Db::commit();
- } catch (\Exception $e) {
- dump($e->getMessage());
- Db::rollBack();
- throw new BusinessException("数据错误");
- }
- // $data['join_pay_order_id'] = $orderGroupId;
- // $data['join_pay_object_json'] = json_encode(['order_id' => $orderId]);
- $rate = 0;
- if (!empty($goods->goods_attribute_json)) {
- $attributeJson = json_decode($goods->goods_attribute_json, true);
- $rate = $attributeJson['added'] ? $attributeJson['added']['nbr'] : 0;
- }
- $extendJson['added_amount'] = number_format($data['pay_amount'] * $rate, 2, '.', '');
- $extendJson['added_rate'] = $rate;
- } else {
- // $extendJson['notify'] = 'success';
- $extendJson['is_custom'] = $params['is_custom'];
- }
- $data['pay_extend_json'] = json_encode($extendJson);
- $data['pay_paytimes'] = date('Y-m-d H:i:s', strtotime($data['pay_paytimes']));
- $data['pay_prepayid'] = 0;
- return $data;
- }
- }
|