Order.php 25 KB

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