Index.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. //测试脚本
  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. public function reset_user_pledge()
  40. {
  41. $list = UserPledge::where('status', 1)->select();
  42. $ids = '';
  43. foreach ($list as $item){
  44. $info = json_decode($item->details, true);
  45. foreach ($info as $value){
  46. $ids .= $value->id . ',';
  47. }
  48. }
  49. dump($ids);
  50. }
  51. //去掉重复订单
  52. public function removeOrder(ProductOrder $productOrder) {
  53. $i = 0;
  54. $rows = Db::name('product_order')->field('id,order_no,count(*) as count')->group('order_no')->having('count > 1')->limit(500)->select();
  55. foreach ($rows as $row) {
  56. $order = $productOrder::where('order_no', $row['order_no'])->order('id asc')->select();
  57. foreach ($order as $key => $vv) {
  58. if($key > 0){
  59. $vv->order_no = $row['order_no']. $key;
  60. $vv->save();
  61. $i++;
  62. }
  63. }
  64. }
  65. // 如果需要,可以在这里进行一些批量操作
  66. $this->success('ok:'. $i);
  67. }
  68. public function check_is_super() {
  69. $i = 0;
  70. $rows = Db::name('product_order')->field('id,order_no,count(*) as count')->group('order_no')->having('count > 1')->limit(500)->select();
  71. foreach ($rows as $row) {
  72. $order = $productOrder::where('order_no', $row['order_no'])->order('id asc')->select();
  73. foreach ($order as $key => $vv) {
  74. if($key > 0){
  75. $vv->order_no = $row['order_no']. $key;
  76. $vv->save();
  77. $i++;
  78. }
  79. }
  80. }
  81. // 如果需要,可以在这里进行一些批量操作
  82. $this->success('ok:'. $i);
  83. }
  84. }