Index.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\model\ProductOrder;
  5. use fast\Asset;
  6. use app\common\model\LedgerTeacChangeModel;
  7. use app\common\model\LedgerWalletModel;
  8. use app\common\model\UserPledge;
  9. use think\Db;
  10. /**
  11. * 首页接口
  12. */
  13. class Index extends Api
  14. {
  15. protected array $noNeedLogin = ['*'];
  16. private $loaded = false;
  17. private $data;
  18. //测试脚本
  19. public function task(UserPledge $userPledge, ProductOrder $productOrder, LedgerWalletModel $ledgerWalletModel) {
  20. //$rows = UserPledge::where('status', '=', 1)->select();
  21. $list = $userPledge::alias('a')
  22. ->join('product_pledge b', 'a.pledge_id = b.id', 'left')
  23. ->where('a.status', '>', 0)
  24. ->field('a.*,b.day_num')
  25. ->select();
  26. $i = 0;
  27. $time= time();
  28. $day = 86400;
  29. foreach ($list as $item) {
  30. //修改详情订单状态
  31. $detail = json_decode($item['details'], true);
  32. $productOrder::where('status', 6)->whereIn('id', array_column($detail, 'id'))->setField('status', ProductOrder::Paid);
  33. //更新存储订单状态
  34. $item->last_time = $time;
  35. $item->status = 0; //关闭
  36. $item->save();
  37. $i++;
  38. }
  39. $this->success('ok:'. $i);
  40. }
  41. //去掉重复订单
  42. public function removeOrder(ProductOrder $productOrder) {
  43. $i = 0;
  44. $rows = Db::name('product_order')->field('id,order_no,count(*) as count')->group('order_no')->having('count > 1')->limit(500)->select();
  45. foreach ($rows as $row) {
  46. $order = $productOrder::where('id', $row['id'])->order('id asc')->select();
  47. foreach ($order as $key => $vv) {
  48. if($key > 0){
  49. $vv->order_no = $row['order_no']. $key;
  50. $vv->save();
  51. $i++;
  52. }
  53. }
  54. }
  55. // 如果需要,可以在这里进行一些批量操作
  56. $this->success('ok:'. $i);
  57. }
  58. }