Index.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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\UserModel;
  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. //测试脚本
  17. public function task(UserPledge $userPledge, ProductOrder $productOrder, LedgerWalletModel $ledgerWalletModel) {
  18. //$rows = UserPledge::where('status', '=', 1)->select();
  19. $list = $userPledge::alias('a')
  20. ->join('product_pledge b', 'a.pledge_id = b.id', 'left')
  21. ->where('a.status', '>', 0)
  22. ->field('a.*,b.day_num')
  23. ->select();
  24. $i = 0;
  25. $time= time();
  26. $day = 86400;
  27. foreach ($list as $item) {
  28. //修改详情订单状态
  29. $detail = json_decode($item['details'], true);
  30. $productOrder::where('status', 6)->whereIn('id', array_column($detail, 'id'))->setField('status', ProductOrder::Paid);
  31. //更新存储订单状态
  32. $item->last_time = $time;
  33. $item->status = 0; //关闭
  34. $item->save();
  35. $i++;
  36. }
  37. $this->success('ok:'. $i);
  38. }
  39. //空投产品
  40. public function reset_user_pledge()
  41. {
  42. $productOrder = new ProductOrder(); //Loader::model('ProductOrder');
  43. $count = 0;
  44. UserModel::chunk(500, function($items) use ($count, $productOrder) {
  45. foreach ($items as $item) {
  46. // 处理每个数据项
  47. $productOrder::setPopularNoAreaOrder(6, 0, 0, 14, $item->id, 5);
  48. $count ++;
  49. }
  50. });
  51. dump("总计:".$count);
  52. }
  53. //去掉重复订单
  54. public function removeOrder(ProductOrder $productOrder) {
  55. $i = 0;
  56. $rows = Db::name('product_order')->field('id,order_no,count(*) as count')->group('order_no')->having('count > 1')->limit(500)->select();
  57. foreach ($rows as $row) {
  58. $order = $productOrder::where('order_no', $row['order_no'])->order('id asc')->select();
  59. foreach ($order as $key => $vv) {
  60. if($key > 0){
  61. $vv->order_no = $row['order_no']. $key;
  62. $vv->save();
  63. $i++;
  64. }
  65. }
  66. }
  67. // 如果需要,可以在这里进行一些批量操作
  68. $this->success('ok:'. $i);
  69. }
  70. public function check_is_super() {
  71. $i = 0;
  72. $rows = Db::name('product_order')->field('id,order_no,count(*) as count')->group('order_no')->having('count > 1')->limit(500)->select();
  73. foreach ($rows as $row) {
  74. $order = $productOrder::where('order_no', $row['order_no'])->order('id asc')->select();
  75. foreach ($order as $key => $vv) {
  76. if($key > 0){
  77. $vv->order_no = $row['order_no']. $key;
  78. $vv->save();
  79. $i++;
  80. }
  81. }
  82. }
  83. // 如果需要,可以在这里进行一些批量操作
  84. $this->success('ok:'. $i);
  85. }
  86. }