You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OrderInfo.php 3.3 KiB

3 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace common\models;
  3. use yii\db\ActiveRecord;
  4. use yii\db\Exception;
  5. use yii\db\Expression;
  6. /**
  7. * This is the model class for table "order_info".
  8. *
  9. * @property integer $id
  10. * @property integer $order_id
  11. * @property integer $prod_id
  12. * @property integer $count
  13. * @property string $unit_price
  14. * @property string $total price
  15. * @property integer $delete_flag
  16. */
  17. class OrderInfo extends ActiveRecord
  18. {
  19. /**
  20. * @inheritdoc
  21. */
  22. public static function tableName()
  23. {
  24. return 'order_info';
  25. }
  26. /**
  27. * @inheritdoc
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['order_id', 'prod_id', 'count', 'delete_flag'], 'integer'],
  33. [['unit_price', 'total_price','commission'], 'number'],
  34. ];
  35. }
  36. /**
  37. * @inheritdoc
  38. */
  39. public function attributeLabels()
  40. {
  41. return [
  42. 'id' => 'ID',
  43. 'order_id' => 'Order ID',
  44. 'prod_id' => 'Prod ID',
  45. 'count' => 'Count',
  46. 'unit_price' => 'Unit Price',
  47. 'total_price' => 'Total Price',
  48. 'delete_flag' => 'Delete Flag',
  49. ];
  50. }
  51. /**
  52. * Function Description:插入子订单
  53. * Function Name: insertInfo
  54. * @param $prod_arr
  55. * @param $oderId
  56. *
  57. * @return bool
  58. *
  59. * @author 娄梦宁
  60. */
  61. public function insertInfo($prod_arr, $oderId)
  62. {
  63. $sql = "INSERT into order_info(order_id, total_price, count, unit_price, prod_id,commission)
  64. SELECT {$oderId}, prod_price*{$prod_arr['prod_count']} price,
  65. {$prod_arr['prod_count']},prod_price,prod_id,commission
  66. from prod_main
  67. where prod_id ={$prod_arr['prod_id']}";
  68. $res = $this->getDb()->createCommand($sql)->execute();
  69. if (!$res) {
  70. return false;
  71. }
  72. return true;
  73. }
  74. /**
  75. * Function Description:获取订单佣金
  76. * Function Name: insertInfo
  77. * @param $orderId int
  78. * @return int
  79. * @author 娄梦宁
  80. */
  81. public function getOrderCommission($orderId)
  82. {
  83. $select = [
  84. new Expression("IFNULL(SUM(b.commission*a.count),0) 'commission'"),
  85. 'order_id'
  86. ];
  87. try{
  88. $result =self::find()->select($select)
  89. ->from(self::tableName().' as a')
  90. ->innerJoin(ProdMain::tableName().' as b','a.prod_id = b.prod_id')
  91. ->where(['=','a.order_id',$orderId])
  92. ->asArray()
  93. ->one();
  94. }catch (Exception $e) {
  95. $result['commission'] = 0;
  96. }
  97. return $result['commission'];
  98. }
  99. /**
  100. * Des:获取产品数组
  101. * Name: getFreeWalkProdArr
  102. * @param $order_id
  103. * @return array
  104. * @author 倪宗锋
  105. */
  106. public function geProdArr($order_id){
  107. $select = [
  108. 'prod_id'=> 'b.bus_id',
  109. 'prod_name'=> 'b.prod_name',
  110. 'prod_num' => 'a.count'
  111. ];
  112. $where = ['=','a.order_id', $order_id];
  113. $getProdArr = self::find()->select($select)
  114. ->from(self::tableName().' a')
  115. ->innerJoin(ProdMain::tableName().' b','a.prod_id = b.prod_id')
  116. ->where($where)
  117. ->asArray(true)
  118. ->all();
  119. return $getProdArr;
  120. }
  121. }