20220223074044_create_order_tj_table.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. use think\migration\Migrator;
  3. use think\migration\db\Column;
  4. class CreateOrderTjTable extends Migrator
  5. {
  6. /**
  7. * Change Method.
  8. *
  9. * Write your reversible migrations using this method.
  10. *
  11. * More information on writing migrations is available here:
  12. * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
  13. *
  14. * The following commands can be used in this method and Phinx will
  15. * automatically reverse them when rolling back:
  16. *
  17. * createTable
  18. * renameTable
  19. * addColumn
  20. * renameColumn
  21. * addIndex
  22. * addForeignKey
  23. *
  24. * Remember to call "create()" or "update()" and NOT "save()" when working
  25. * with the Table class.
  26. */
  27. /*
  28. SELECT sum(total_price+express_price) as t1,
  29. sum(total_price) as t2,sum(pay_price+rice_card_money+rice_card_express_money) as t3,sum(express_price) as t4,
  30. sum(coupon_money) as t5,count(distinct(user_id)) as t6,count(*) as t7
  31. $t1 = $result[0]['t1'];//应付总金额(含运费)
  32. $t2 = $result[0]['t2'];//应付商品总金额
  33. $t3 = $result[0]['t3'];//实付金额(含运费)
  34. $t4 = $result[0]['t4'];//运费
  35. $t5 = $result[0]['t5'];//平台优惠券抵扣
  36. $t6 = $result[0]['t6'];//成交用户数
  37. $t7 = $result[0]['t7'];//订单数
  38. $t8 = $t3/$t6; //客单价
  39. */
  40. public function change()
  41. {
  42. $table = $this->table('order_tj',array('id' => true,'primary_key' => ['id'],'engine'=>'InnoDB','comment'=>'订单统计记录'));
  43. $table->addColumn('create_time', 'integer', array('limit' => 10,'signed' => false, 'default' => 0, 'comment' => '创建时间'))
  44. ->addColumn('remark', 'string',array('limit' => 255,'default'=>'','comment'=>'备注'))
  45. ->addColumn('ftype', 'integer',array('limit' => 10,'default'=>0,'comment'=>'1:日,2:周,3:月'))
  46. ->addColumn('total_price', 'decimal',array('limit' => 11,'precision'=>10,'scale'=>2,'signed'=>false,'default'=>0,'comment'=>'应付总金额(含运费)'))
  47. ->addColumn('total_goods_price', 'decimal',array('limit' => 11,'precision'=>10,'scale'=>2,'signed'=>false,'default'=>0,'comment'=>'应付商品总金额'))
  48. ->addColumn('total_pay_price', 'decimal',array('limit' => 11,'precision'=>10,'scale'=>2,'signed'=>false,'default'=>0,'comment'=>'实付金额(含运费)'))
  49. ->addColumn('total_express_price', 'decimal',array('limit' =>11,'precision'=>10,'scale'=>2,'signed'=>false,'default'=>0,'comment'=>'运费)'))
  50. ->addColumn('total_coupon_price', 'decimal',array('limit' => 11,'precision'=>10,'scale'=>2,'signed'=>false,'default'=>0,'comment'=>'平台优惠券抵扣)'))
  51. ->addColumn('total_users', 'integer',array('limit' => 11,'signed'=>false,'default'=>0,'comment'=>'成交用户数)'))
  52. ->addColumn('total_orders', 'integer',array('limit' => 11,'signed'=>false,'default'=>0,'comment'=>'成交订单数)'))
  53. ->addColumn('pcts', 'decimal',array('limit' => 11,'precision'=>10,'scale'=>2,'signed'=>false,'default'=>0,'comment'=>'客单价'))
  54. ->addColumn('tj_time', 'datetime', array('comment' => '统计时间'))
  55. ->create();
  56. }
  57. }