GenHistoryShopDailySalesSeeder.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. use app\api\model\shop\Shops;
  3. use app\api\model\Order;
  4. use app\common\model\ShopsDailySalesSt;
  5. use think\migration\Seeder;
  6. use think\facade\Db;
  7. class GenHistoryShopDailySalesSeeder extends Seeder
  8. {
  9. /**
  10. * Run Method.
  11. *
  12. * Write your database seeder using this method.
  13. *
  14. * More information on writing seeders is available here:
  15. * http://docs.phinx.org/en/latest/seeding.html
  16. */
  17. public function run()
  18. {
  19. $shops = Shops::where('is_delete',0)->field('shop_id,province_id,city_id,region_id')->select();
  20. Db::execute("truncate table yoshop_shop_daily_sales_st");
  21. $m = new ShopsDailySalesSt();
  22. $orderM = new Order();
  23. $datas = [];
  24. $baseTo = strtotime(date("Y-m-d"),time());
  25. $now = time();
  26. for ($i=1;$i<72;$i++){
  27. foreach ($shops as $shop) {
  28. $from = $baseTo - 86400*$i;
  29. $dayMid = $from + 43200;
  30. $to = $from + 86399;
  31. $temp = [];
  32. $tj = $orderM->dailySalesTj($shop['shop_id'],$from,$to);
  33. $temp['total_price'] = $tj['total_price'];
  34. $temp['total_goods_price'] = $tj['total_goods_price'];
  35. $temp['total_pay_price'] = $tj['total_pay_price'];
  36. $temp['coupon_money'] = $tj['coupon_money'];
  37. $temp['order_count'] = $tj['order_count'];
  38. $temp['express_price'] = $tj['express_price'];
  39. $temp['boss_comm_money'] = $tj['boss_comm_money'];
  40. $temp['mg_comm_money'] = $tj['mg_comm_money'];
  41. $temp['seller_comm_money'] = $tj['seller_comm_money'];
  42. $temp['shop_id'] = $shop['shop_id'];
  43. $temp['st_time'] = $dayMid;
  44. $temp['create_time'] = $now;
  45. $temp['update_time'] = $now;
  46. $datas[] = $temp;
  47. }
  48. }
  49. $m->insertAll($datas);
  50. }
  51. }