OrderGoods.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace app\model;
  3. use think\Model;
  4. class OrderGoods extends Model
  5. {
  6. protected $connection = 'mysql';
  7. protected $pk = 'id';
  8. protected $name = 'order_goods';
  9. public function goods()
  10. {
  11. return $this->hasOne(Goods::class, 'id', 'goods_id');
  12. }
  13. function getOrderGoods($order_id)
  14. {
  15. $data = $this::where(['order_id' => $order_id])->select()->toArray();
  16. foreach ($data as &$vo) {
  17. if (empty($vo["image"])) {
  18. $goods = Goods::where(['id' => $vo['goods_id']])->find();
  19. if (!empty($goods)) {
  20. $goods = $goods->toArray();
  21. }
  22. if (!empty($goods)) {
  23. $vo['pic'] = toimg($goods['image']);
  24. $vo['image'] = toimg($goods['image']);
  25. }
  26. } else {
  27. $vo['image'] = toimg($vo['image']);
  28. $vo['pic'] = toimg($vo['image']);
  29. }
  30. $vo['label'] = $vo['sku'];
  31. }
  32. return $data;
  33. }
  34. public static function getOrderGoodsids($order_id)
  35. {
  36. $data = OrderGoods::where(['order_id' => $order_id])->select()->toArray();
  37. $ids = '';
  38. foreach ($data as &$vo) {
  39. if ($vo['goods_id'] > 0) {
  40. if ($ids == '') {
  41. $ids = $vo['goods_id'];
  42. } else {
  43. $ids = $ids . ',' . $vo['goods_id'];
  44. }
  45. }
  46. }
  47. return $ids;
  48. }
  49. public static function getCommission($order_info, $roletype, $percent)
  50. {
  51. $total = 0.00;
  52. $OrderGoods = OrderGoods::where(['order_id' => $order_info['id']])
  53. ->select()
  54. ->toArray();
  55. foreach ($OrderGoods as $vo) {
  56. if (!empty($vo['goods_id'])) {
  57. if ($vo['card_tid'] > 0 && !empty($roletype)) {
  58. $GiftcardCommission = GoodsGiftcardCommission::where('card_tid', $vo['card_tid'])->where('roletype', $roletype)->find();
  59. if (!empty($GiftcardCommission)) {
  60. $GiftcardCommission = $GiftcardCommission->toArray();
  61. if ($GiftcardCommission['commission_method'] == 0) {
  62. $total = $total + (($vo['total'] * percent_to_num($GiftcardCommission['return_percent'])));
  63. } elseif ($GiftcardCommission['commission_method'] == 1) {
  64. $total = $total + (($GiftcardCommission['return_percent'] * $vo['quantity']));
  65. }
  66. }
  67. } elseif ($vo['is_commission'] == 1) {
  68. if ($vo['commission_price'] > 0) {
  69. if ($vo['commission_method'] == 0) {
  70. $total = $total + (($vo['total'] * percent_to_num($vo['commission_price'])) * percent_to_num($percent));
  71. } elseif ($vo['commission_method'] == 1) {
  72. $total = $total + (($vo['commission_price'] * $vo['quantity']) * percent_to_num($percent));
  73. }
  74. }
  75. } else {
  76. $total += ($vo['total'] * percent_to_num($percent));
  77. }
  78. }
  79. }
  80. return $total;
  81. }
  82. }