OrderGoodsCalculate.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace addon\store\event;
  13. use addon\cashier\model\order\CashierOrderPay;
  14. /**
  15. * 订单项计算
  16. */
  17. class OrderGoodsCalculate
  18. {
  19. public function handle($data)
  20. {
  21. $store_id = $data[ 'store_id' ] ?? 0;
  22. if ($store_id > 0) {
  23. $site_id = $data[ 'site_id' ];
  24. //还需要判断配送方式(平台运营模式如果是 同城 门店自提的话 才有可能传入store_id)
  25. $delivery_array = $data[ 'delivery' ] ?? [];
  26. $delivery_type = $delivery_array[ 'delivery_type' ] ?? 'express';
  27. $store_config_model = new \addon\store\model\Config();
  28. $store_config = $store_config_model->getStoreBusinessConfig($site_id)[ 'data' ][ 'value' ] ?? [];
  29. if ($store_config[ 'store_business' ] == 'shop' && !in_array($delivery_type, [ 'local', 'store' ])) {
  30. return null;
  31. }
  32. $goods_id = $data[ 'goods_id' ];
  33. $goods_info = model('goods')->getInfo([ [ 'goods_id', '=', $goods_id ] ], 'sale_store');
  34. $sale_store = $goods_info[ 'sale_store' ] ?? '';
  35. if ($sale_store != 'all') {
  36. $sale_store_ids = explode(',', $sale_store);
  37. if (!in_array($store_id, $sale_store_ids)) {
  38. $error = array (
  39. // 'code' => '',//暂无映射关系
  40. 'message' => '当前门店暂不支持销售此项商品'
  41. );
  42. $data[ 'error' ] = $error;
  43. return ( new CashierOrderPay() )->success($data);
  44. }
  45. }
  46. $sku_id = $data[ 'sku_id' ];
  47. $store_sku_condition = array (
  48. [ 'sku_id', '=', $sku_id ],
  49. [ 'store_id', '=', $store_id ]
  50. );
  51. $store_sku_info = model('store_goods_sku')->getInfo($store_sku_condition);
  52. if (!empty($store_sku_info)) {
  53. $is_unify_pirce = $data[ 'is_unify_pirce' ];
  54. if ($is_unify_pirce == 1) {
  55. //表逻辑,无实际意义
  56. } else {
  57. $data[ 'price' ] = $store_sku_info[ 'price' ];
  58. }
  59. $data[ 'stock' ] = numberFormat($store_sku_info[ 'stock' ]);
  60. if ($store_sku_info[ 'status' ] != 1) {
  61. $error = array (
  62. // 'code' => '',//暂无映射关系
  63. 'message' => '当前门店暂不支持销售此项商品'
  64. );
  65. }
  66. } else {
  67. $error = array (
  68. // 'code' => '',//暂无映射关系
  69. 'message' => '当前门店暂不支持销售此项商品'
  70. );
  71. }
  72. if (!empty($error)) {
  73. $data[ 'error' ] = $error;
  74. }
  75. return ( new CashierOrderPay() )->success($data);
  76. }
  77. }
  78. }