Order.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author Qinii
  6. * @day 2020-06-15
  7. *
  8. *
  9. */
  10. namespace app\controller\admin\order;
  11. use crmeb\basic\BaseController;
  12. use app\common\repositories\store\ExcelRepository;
  13. use app\common\repositories\system\merchant\MerchantRepository;
  14. use app\common\repositories\store\order\StoreOrderRepository as repository;
  15. use crmeb\services\SpreadsheetExcelService;
  16. use think\App;
  17. use think\facade\Db;
  18. class Order extends BaseController
  19. {
  20. protected $repository;
  21. public function __construct(App $app, repository $repository)
  22. {
  23. parent::__construct($app);
  24. $this->repository = $repository;
  25. }
  26. public function lst($id)
  27. {
  28. [$page, $limit] = $this->getPage();
  29. $where = $this->request->params(['date','order_sn','order_type','keywords','username']);
  30. $where['reconciliation_type'] = $this->request->param('status', 1);
  31. $where['mer_id'] = $id;
  32. return app('json')->success($this->repository->adminGetList($where, $page, $limit));
  33. }
  34. public function markForm($id)
  35. {
  36. if (!$this->repository->getWhereCount([$this->repository->getPk() => $id]))
  37. return app('json')->fail('数据不存在');
  38. return app('json')->success(formToData($this->repository->adminMarkForm($id)));
  39. }
  40. public function mark($id)
  41. {
  42. if (!$this->repository->getWhereCount([$this->repository->getPk() => $id]))
  43. return app('json')->fail('数据不存在');
  44. $data = $this->request->params(['admin_mark']);
  45. $this->repository->update($id, $data);
  46. return app('json')->success('备注成功');
  47. }
  48. /**
  49. * TODO
  50. * @return mixed
  51. * @author Qinii
  52. * @day 2020-06-25
  53. */
  54. public function getAllList()
  55. {
  56. [$page, $limit] = $this->getPage();
  57. $where = $this->request->params(['type', 'date', 'mer_id','keywords','status','username','order_sn','order_ids','paid', 'zero_line_uid']);
  58. $pay_type=$this->request->param('pay_type');
  59. if($pay_type==1 || $pay_type==4){
  60. $where['pay_type']=$pay_type;
  61. }
  62. if($pay_type==6){
  63. //一壶茶红积分兑换的
  64. $where['mer_id']=496;
  65. $where['pay_type']=5;
  66. }
  67. // 导出
  68. $is_excel = request()->param('is_excel', 0);
  69. $result = $this->repository->merchantGetList($where, $page, $limit, $is_excel);
  70. if ($is_excel == 1) {
  71. $data = $result['list'];
  72. $arr = [];
  73. foreach ($data as $item) {
  74. $arr[] = [
  75. $item['order_sn'], // 订单编号
  76. $item['order_type'] == 0 ? "普通订单" : "核销订单", // 订单类型
  77. $item['user']['nickname'] ?? '', // 用户昵称
  78. $item['user']['phone'] ?? '', // 用户手机号
  79. $item['real_name'], // 收货人
  80. $item['merchant']['mer_name'] ?? '', // 商户名称
  81. // $item['orderProduct'][0]['cart_info']['product']['image'],
  82. ($item['orderProduct'][0]['cart_info']['product']['store_name'] ?? '') . ' | ' . ($item['orderProduct'][0]['cart_info']['productAttr']['sku'] ?? ''),
  83. $item['orderProduct'][0]['cart_info']['productAttr']['price'] ?? 0.00,
  84. $item['orderProduct'][0]['product_num'] ?? 0,
  85. $item['pay_price'], // 订单金额
  86. $item['paid'] == 0 ? "未支付" : "已支付", // 支付状态
  87. $item['fzone_pay_note'], // 支付方式
  88. $item['fzone_pay_jifen'], // 支付方式
  89. $item['fzone_pay_price'], // 支付方式
  90. $item['fzone_pay_jingdou'], // 支付方式
  91. $item['fzone_pay_vr'], // 支付方式
  92. $item['is_del'] == 0 ? ($item['status'] == 5 ? '待付款' : ($item['status'] == 0 ? '待发货' : ($item['status'] == 1 ? '待收货' : ($item['status'] == 2 ? '待评价' : ($item['status'] == 3 ? '已完成' : ($item['status'] == 4 ? '已申请退款' : ($item['status'] == -1 ? '已退款' : ($item['status'] == 6 ? '已取消' : '')))))))) : '已删除', // 订单状态
  93. $item['create_time'], // 下单时间
  94. ];
  95. }
  96. return app('json')->success($this->getStatisticsExcel([
  97. '订单编号',
  98. '订单类型',
  99. '用户昵称',
  100. '用户手机号',
  101. '收货人',
  102. '商户名称',
  103. '商品图片',
  104. // '商品名称',
  105. '商品单价',
  106. '商品数量',
  107. '订单金额',
  108. '支付状态',
  109. '支付方式',
  110. '支付积分',
  111. '支付现金',
  112. '支付京豆',
  113. '支付VR',
  114. '订单状态',
  115. '下单时间'
  116. ], $arr, '订单明细'));
  117. }
  118. return app('json')->success($result);
  119. }
  120. /**
  121. * 获取统计导出
  122. */
  123. public function getStatisticsExcel($header,$arr,$title)
  124. {
  125. $filename = $title.'_'.date('YmdHis').'_'.rand(10000,99999);
  126. $name = $filename;
  127. $info = '生成时间:' . date('Y-m-d H:i:s',time());
  128. $suffix='xlsx';
  129. $path='extract';
  130. unset($_instance);
  131. $_instance = SpreadsheetExcelService::instance_xin();
  132. $_path =$_instance
  133. ->createOrActive()
  134. ->setExcelHeader($header)
  135. ->setExcelTile($title, $name, $info)
  136. ->setExcelContent($arr)
  137. ->excelSave($filename, $suffix, $path);
  138. $domain = request()->domain();
  139. $data= [
  140. 'name' => $filename.'.'.$suffix,
  141. 'status' => 1,
  142. 'path' => $domain.'/'.$_path
  143. ];
  144. return $data;
  145. }
  146. /**
  147. * TODO 自提订单列表
  148. * @return mixed
  149. * @author Qinii
  150. * @day 2020-08-17
  151. */
  152. public function getTakeList()
  153. {
  154. [$page, $limit] = $this->getPage();
  155. $where = $this->request->params(['date','order_sn','keywords','username']);
  156. $where['take_order'] = 1;
  157. $where['status'] = -1;
  158. $where['verify_date'] = $where['date'];
  159. unset($where['date']);
  160. return app('json')->success($this->repository->merchantGetList($where, $page, $limit));
  161. }
  162. /**
  163. * TODO
  164. * @return mixed
  165. * @author Qinii
  166. * @day 2020-08-17
  167. */
  168. public function chart()
  169. {
  170. $where = $this->request->params(['type', 'date', 'mer_id','keywords','username','order_sn','order_ids','paid']);
  171. return app('json')->success($this->repository->adminOrderNumber(-1, $where));
  172. }
  173. /**
  174. * TODO 自提订单头部统计
  175. * @return mixed
  176. * @author Qinii
  177. * @day 2020-08-17
  178. */
  179. public function takeChart()
  180. {
  181. return app('json')->success($this->repository->adminOrderNumber(1));
  182. }
  183. /**
  184. * TODO 订单类型
  185. * @return mixed
  186. * @author Qinii
  187. * @day 2020-08-15
  188. */
  189. public function orderType()
  190. {
  191. return app('json')->success($this->repository->orderType([]));
  192. }
  193. public function detail($id)
  194. {
  195. $data = $this->repository->getOne($id, null);
  196. if (!$data)
  197. return app('json')->fail('数据不存在');
  198. return app('json')->success($data);
  199. }
  200. /**
  201. * TODO 快递查询
  202. * @param $id
  203. * @return mixed
  204. * @author Qinii
  205. * @day 2020-06-25
  206. */
  207. public function express($id)
  208. {
  209. if (!$this->repository->getWhereCount(['order_id' => $id, 'delivery_type' => 1]))
  210. return app('json')->fail('订单信息或状态错误');
  211. return app('json')->success($this->repository->express($id));
  212. }
  213. public function reList($id)
  214. {
  215. [$page, $limit] = $this->getPage();
  216. $where = ['reconciliation_id' => $id, 'type' => 0];
  217. return app('json')->success($this->repository->reconList($where, $page, $limit));
  218. }
  219. /**
  220. * TODO 导出文件
  221. * @author Qinii
  222. * @day 2020-07-30
  223. */
  224. public function excel()
  225. {
  226. $where = $this->request->params(['type', 'date', 'mer_id','keywords','status','username','order_sn']);
  227. app()->make(ExcelRepository::class)->create($where, $this->request->adminId(), 'order',0);
  228. return app('json')->success('开始导出数据');
  229. }
  230. /**
  231. * 养老金打款凭证 列表
  232. * @return mixed
  233. * @throws \think\db\exception\DataNotFoundException
  234. * @throws \think\db\exception\DbException
  235. * @throws \think\db\exception\ModelNotFoundException
  236. */
  237. public function order_red_list()
  238. {
  239. [$page, $limit] = $this->getPage();
  240. $where = $this->request->params(['status', 'date']);
  241. // $where['mer_id'] = $this->request->merId();
  242. $query = Db::name('enterprise_red_order_voucher')->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
  243. getModelTime($query, $where['date']);
  244. })->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
  245. $query->where('status',$where['status']);
  246. });
  247. $data['count'] = $query->count();
  248. $data['list'] = $query->page($page, $limit)->order('id desc')->select();
  249. return app('json')->success('ok', $data);
  250. }
  251. /**
  252. * 养老金提交打款凭证 审核
  253. * @return mixed
  254. * @throws \think\db\exception\DataNotFoundException
  255. * @throws \think\db\exception\DbException
  256. * @throws \think\db\exception\ModelNotFoundException
  257. */
  258. public function order_red_status()
  259. {
  260. $post= $this->request->params(['id', 'status', 'refund_message']);
  261. $voucher=Db::name('enterprise_red_order_voucher')->find($post['id']);
  262. if(!$voucher){
  263. return app('json')->fail('订单信息错误');
  264. }
  265. if($voucher['status']!=0){
  266. return app('json')->fail('请勿重复操作');
  267. }
  268. if($post['status']==2){
  269. $update['status']=2;
  270. $update['refund_message']=$post['refund_message'];
  271. if($post['refund_message']==''){
  272. return app('json')->fail('请输入不通过原因');
  273. }
  274. $is_red_ylj=0;
  275. }else{
  276. $update['status']=1;
  277. $is_red_ylj=2;
  278. }
  279. $update['status_time']=date('Y-m-d H:i:s');
  280. $re=Db::name('enterprise_red_order_voucher')->where('id',$post['id'])->update($update);
  281. Db::name('store_order')->whereIn('order_id',$voucher['order_ids'])->where('is_red_ylj',1)->update(['is_red_ylj'=>$is_red_ylj]);
  282. $where['o.paid'] = 1;
  283. // $where['o.pay_type'] = 5;
  284. $where['u.commission_type'] = 5;
  285. $where['u.gzc'] = 3;
  286. $where['u.status'] = 0;
  287. $bill_id = Db::name('store_order')
  288. ->alias('o')
  289. ->join('user_bill u', 'u.order_sn=o.order_sn')
  290. ->where($where)
  291. ->whereIN('o.pay_type',[0,5])
  292. ->whereIn('o.order_id', $voucher['order_ids'])
  293. ->column('u.bill_id');
  294. Db::name('user_bill')->whereIn('bill_id',$bill_id)->update(['status'=>1,'gzc'=>0]);
  295. if($re){
  296. return app('json')->success('操作成功');
  297. }
  298. return app('json')->fail('操作失败');
  299. }
  300. /**
  301. * 撤回订单,并撤回订单奖励
  302. */
  303. public function killOrderRewards(){
  304. $group_order_id = request()->param('group_order_id');
  305. $order_id = request()->param('order_id');
  306. $uid = request()->param('uid');
  307. if (empty($order_id) || empty($group_order_id) || empty($uid)) {
  308. return app('json')->fail('参数缺失');
  309. }
  310. try {
  311. Db::startTrans();
  312. //查找是否有推荐人
  313. $spreadUid = Db::name('user')->where('uid', $uid)->value('spread_uid');
  314. //取出pv
  315. $pv = $this->getValue('user_pv_log', [['order_id', '=', $order_id], ['status', '=', 1],], 'pv');
  316. //取出 vr
  317. $payVr = $this->getValue('user_sign_vr', [['order_id', '=', $order_id], ['type', '=', 2],], 'number');
  318. //取出购买赠送积分 / 支出积分
  319. $score = $this->getValue('user_sign_score', [['order_id', '=', $order_id], ['status', '=', 1], ['source_type', '=', 3], ['uid', '=', $uid], ['pm', '=', 1],], 'reward_socre');
  320. $payScore = $this->getValue('user_sign_score', [['order_id', '=', $order_id], ['status', '=', 1], ['pm', '=', 2], ['uid', '=', $uid],], 'reward_socre');
  321. // 贡献值
  322. $gongXian = $this->getValue('user_sign_gongxian', [['order_id', '=', $order_id], ['status', '=', 1], ['type', '=', 1], ['uid', '=', $uid],], 'number');
  323. // 养老金
  324. $yangLaoJin = $this->getValue('user_bill', [['link_id', '=', $order_id], ['status', '=', 1], ['pm', '=', 1], ['uid', '=', $uid],], 'number');
  325. if($spreadUid){
  326. $spreadScore = 0;
  327. $spreadGongXian = 0;
  328. $spreadYlj = 0;
  329. $spreadYongJin = 0;
  330. $spreadScore = $this->getValue('user_sign_score', [['order_id', '=', $order_id], ['uid', '=', $spreadUid], ['status', '=', 1],], 'reward_socre');
  331. $spreadGongXian = $this->getValue('user_sign_gongxian', [['order_id', '=', $order_id], ['status', '=', 1], ['type', '=', 1], ['uid', '=', $spreadUid],], 'number');
  332. $spreadYlj = $this->getValue('user_bill', [['link_id', '=', $order_id], ['commission_type', '=', 5], ['uid', '=', $spreadUid],], 'number'); //推荐获得养老金
  333. $spreadYongJin = $this->getValue('user_bill', [['link_id', '=', $order_id], ['commission_type', '=', 3], ['uid', '=', $spreadUid],], 'number'); //推荐获得佣金
  334. $spreadUser = Db::name('user')->where('uid', $spreadUid)->find();
  335. Db::name('backup_user')->insert($spreadUser);
  336. Db::name('user')->where('uid', $spreadUid)
  337. ->update([
  338. 'score' => Db::raw("score - {$spreadScore}"),
  339. 'per_contribute' => Db::raw("per_contribute - {$spreadGongXian}"),
  340. 'brokerage_price' => Db::raw("brokerage_price - {$spreadYongJin}"),
  341. 'annuity' => Db::raw("annuity - {$spreadYlj}"),
  342. ]);
  343. $userhjm1 =[
  344. 'uid' => $spreadUid,
  345. 'order_id' => $order_id,
  346. 'score' => $spreadScore,
  347. 'per_contribute' => $spreadGongXian,
  348. 'brokerage_price' => $spreadYongJin,
  349. 'user' => 2,
  350. ];
  351. Db::name('backup_user_change')->insert($userhjm1);
  352. }
  353. //扫吗消费
  354. $smSpreadUid = $this->getValue('user_sign_score', [['order_id', '=', $order_id], ['mark','like','%扫码%'], ['status', '=', 1],], 'uid');
  355. $smSpreadScore = $this->getValue('user_sign_score', [['order_id', '=', $order_id], ['uid','=',$smSpreadUid], ['status', '=', 1],], 'reward_socre');
  356. //第二推荐
  357. $spreadYongJinTwoUid = $this->getValue('user_bill', [['link_id', '=', $order_id], ['commission_type', '=', 3], ['uid', 'not in', [$uid, $spreadUid]],], 'uid');
  358. $spreadYongJinTwo = $this->getValue('user_bill', [['link_id', '=', $order_id], ['commission_type', '=', 3], ['uid', '=', $spreadYongJinTwoUid],], 'number');
  359. //更新对应的user表
  360. $uscore = $payScore - $score;
  361. $user = Db::name('user')->where('uid', $uid)->find();
  362. Db::name('backup_user')->insert($user);
  363. Db::name('user')->where('uid', $uid)
  364. ->update([
  365. 'pv' => Db::raw("pv - {$pv}"),
  366. 'vr' => Db::raw("vr + {$payVr}"),
  367. 'score' => Db::raw("score + {$uscore}"),
  368. 'contribute' => Db::raw("contribute - {$gongXian}"),
  369. 'annuity' => Db::raw("annuity - {$yangLaoJin}"),
  370. ]);
  371. $userhjm =[
  372. 'uid' => $uid,
  373. 'order_id' => $order_id,
  374. 'pv' => $pv,
  375. 'vr' => $payVr,
  376. 'score' => $uscore,
  377. 'contribute' => $gongXian,
  378. 'annuity' => $yangLaoJin,
  379. 'user' => 1,
  380. ];
  381. Db::name('backup_user_change')->insert($userhjm);//具体修改插入对应表
  382. //第二推荐
  383. if($spreadYongJinTwoUid) {
  384. $spreadUserTwo = Db::name('user')->where('uid', $spreadYongJinTwoUid)->find();
  385. Db::name('backup_user')->insert($spreadUserTwo);
  386. Db::name('user')->where('uid', $spreadYongJinTwoUid)->dec('brokerage_price', $spreadYongJinTwo)->update();
  387. $userhjm2 =[
  388. 'uid' => $spreadYongJinTwoUid,
  389. 'order_id' => $order_id,
  390. 'brokerage_price' => $spreadYongJinTwo,
  391. 'user' => 3,
  392. ];
  393. Db::name('backup_user_change')->insert($userhjm2);
  394. }//扫码消费
  395. if($smSpreadUid){
  396. $smUserTwo = Db::name('user')->where('uid', $smSpreadUid)->find();
  397. Db::name('backup_user')->insert($smUserTwo);
  398. Db::name('user')->where('uid', $smSpreadUid)->dec('score', $smSpreadScore)->update();
  399. $userhjm3 =[
  400. 'uid' => $smSpreadUid,
  401. 'order_id' => $order_id,
  402. 'score' => $smSpreadScore,
  403. 'user' => 4,
  404. ];
  405. Db::name('backup_user_change')->insert($userhjm3);
  406. }
  407. // 删除订单相关表p;
  408. $this->backupAndDelete('store_order', ['group_order_id' => $group_order_id]);
  409. $this->backupAndDelete('store_group_order', ['group_order_id' => $group_order_id]);
  410. $this->backupAndDelete('user_pv_log', ['order_id' => $order_id]);
  411. $this->backupAndDelete('user_sign_vr', ['order_id' => $order_id]);
  412. $this->backupAndDelete('user_sign_score', ['order_id' => $order_id]);
  413. $this->backupAndDelete('user_sign_gongxian', ['order_id' => $order_id]);
  414. $this->backupAndDelete('user_bill', ['link_id' => $order_id]);
  415. $this->backupAndDelete('gzc_logs', ['link_id' => $order_id]);
  416. Db::commit();
  417. } catch (\Exception $e) {
  418. Db::rollback();
  419. return app('json')->fail('操作失败'. $e->getMessage());
  420. }
  421. return app('json')->success('操作成功');
  422. }
  423. private function backupAndDelete($table, array $where)//备份并删除
  424. {
  425. $backupTable = 'backup_' . $table;
  426. $rows = Db::name($table)->where($where)->select()->toArray();
  427. if ($rows) {
  428. Db::name($backupTable)->insertAll($rows);
  429. Db::name($table)->where($where)->delete();
  430. }
  431. }
  432. private function getValue($table, array $where, string $field, $default = 0)//查找
  433. {
  434. $value = Db::name($table)->where($where)->value($field);
  435. return $value ?? $default;
  436. }
  437. /**
  438. * 展示撤回订单列表
  439. */
  440. public function killOrderLst()
  441. {
  442. $query = Db::name('backup_store_order')->paginate(20)->toArray();
  443. return app('json')->success($query, '获取成功');
  444. }
  445. public function easterKillOrder(){
  446. $group_order_id = request()->param('group_order_id');
  447. $order_id = request()->param('order_id');
  448. if (empty($order_id) || empty($group_order_id)) {
  449. return app('json')->fail('参数缺失');
  450. }
  451. try {
  452. Db::startTrans();
  453. // 恢复订单相关表
  454. $this->easterOrder('store_order', ['group_order_id' => $group_order_id]);
  455. $this->easterOrder('store_group_order', ['group_order_id' => $group_order_id]);
  456. // 恢复 pv
  457. $this->easterOrder('user_pv_log', ['order_id' => $order_id]);
  458. // 恢复 vr
  459. $this->easterOrder('user_sign_vr', ['order_id' => $order_id]);
  460. // 恢复 积分
  461. $this->easterOrder('user_sign_score', ['order_id' => $order_id]);
  462. // 恢复 贡献值
  463. $this->easterOrder('user_sign_gongxian', ['order_id' => $order_id]);
  464. // 恢复 佣金/养老金等
  465. $this->easterOrder('user_bill', ['link_id' => $order_id]);
  466. // 恢复 公证处
  467. $this->easterOrder('gzc_logs', ['link_id' => $order_id]);
  468. //恢复用户奖励
  469. $this->easterOrder('user_change', ['order_id' => $order_id]);
  470. Db::commit();
  471. } catch (\Exception $e) {
  472. Db::rollback();
  473. return app('json')->fail('撤回失败: '.$e->getMessage());
  474. }
  475. return app('json')->success('撤回成功');
  476. }
  477. private function easterOrder($table, array $where)
  478. {
  479. $backupTable = 'backup_' . $table;
  480. $rows = Db::name($backupTable)->where($where)->select()->toArray();
  481. if ($rows) {
  482. foreach ($rows as &$row) {
  483. unset($row['backup_time']);
  484. }
  485. Db::name($table)->insertAll($rows);
  486. Db::name($backupTable)->where($where)->delete();
  487. }
  488. }
  489. private function easterUserAward($table, array $where){
  490. $backupTable = 'backup_' . $table;
  491. $row = Db::name($backupTable)->where($where)->where('user', 1)->field('pv, vr, score, contribute, annuity,uid')->find();
  492. $uid = $row['uid'];
  493. $pv = $row['pv'];
  494. $vr = $row['vr'];
  495. $score= $row['score'];
  496. $contribute = $row['contribute'];
  497. $annuity = $row['annuity'];
  498. Db::name('user') //更新订单用户
  499. ->where('uid', $uid)
  500. ->update([
  501. 'pv' => Db::raw("pv + {$pv}"),
  502. 'vr' => Db::raw("vr - {$vr}"),
  503. 'score' => Db::raw("score - {$score}"),
  504. 'contribute' => Db::raw("contribute + {$contribute}"),
  505. 'annuity' => Db::raw("annuity + {$annuity}"),
  506. ]);
  507. $row2 = Db::name($backupTable)->where($where)->where('user', 2)->field('brokerage_price, score, per_contribute, annuity,uid')->find();
  508. if ($row2) {
  509. $spreadUid = $row2['uid'];
  510. $spreadScore = $row2['score'];
  511. $per_contribute = $row2['per_contribute'];
  512. $spreadAnnuity = $row2['annuity'];
  513. $spreadYongJin = $row2['brokerage_price'];
  514. Db::name('user') //更新推荐人
  515. ->where('uid', $spreadUid)
  516. ->update([
  517. 'score' => Db::raw("score + {$spreadScore}"),
  518. 'contribute' => Db::raw("contribute + {$per_contribute}"),
  519. 'annuity' => Db::raw("annuity + {$spreadAnnuity}"),
  520. 'brokerage_price' => Db::raw("brokerage_price + {$spreadYongJin}"),
  521. ]);
  522. }
  523. $row3 = Db::name($backupTable)->where($where)->where('user', 3)->field('brokerage_price,uid')->find();
  524. if ($row3) {
  525. $spreadUidTwo = $row3['uid'];
  526. $spreadYongJin2 = $row3['brokerage_price'];
  527. Db::name('user')
  528. ->where('uid', $spreadUidTwo)
  529. ->update([
  530. 'brokerage_price' => Db::raw("brokerage_price + {$spreadYongJin2}"),
  531. ]);
  532. }
  533. $row4 = Db::name($backupTable)->where($where)->where('user', 4)->field('score,uid')->find();
  534. if ($row4) {
  535. $spreadUidThree = $row4['uid'];
  536. $spreadScore3 = $row4['score'];
  537. Db::name('user')
  538. ->where('uid', $spreadUidThree)
  539. ->update([
  540. 'score' => Db::raw("score + {$spreadScore3}"),
  541. ]);
  542. }
  543. }
  544. }