ExchangeLogic.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\mobile\logic;
  3. use app\model\AddrModel;
  4. use app\model\CommonModel;
  5. use app\model\CompanyGoodModel;
  6. use app\model\GoodModel;
  7. use app\model\GroupModel;
  8. use app\model\InventoryExchangeModel;
  9. use app\model\OrderModel;
  10. use think\Exception;
  11. use think\facade\Db;
  12. use think\response\Json;
  13. class ExchangeLogic extends BaseLogic
  14. {
  15. //商品列表
  16. public static function goodList(array $data = []): Json
  17. {
  18. $db = CompanyGoodModel::alias('a')
  19. ->leftJoin('good b', 'b.id=a.good_id AND b.is_del=' . CommonModel::$del_normal)
  20. ->leftJoin('inventory_exchange c', 'c.account_id=' . self::$aid . ' AND c.good_id=a.good_id')
  21. ->where(['a.is_del' => CommonModel::$del_normal, 'a.group_id' => self::$group_id, 'b.type' => GoodModel::$type_exchange]);
  22. $count = $db->count('a.id');
  23. $list = $db
  24. ->field('a.id,a.code,a.good_id,b.good_cover_img,b.good_name,b.moq,b.step,c.inventory')
  25. ->page($data['page'], $data['size'])
  26. ->order(['a.is_top' => 'desc', 'a.weight' => 'desc', 'a.id' => 'desc'])
  27. ->select()
  28. ->toArray();
  29. return json_show(CommonModel::$success, '获取兑换商品列表成功', ['count' => $count, 'list' => $list]);
  30. }
  31. //商品详情
  32. public static function goodInfo(string $code = ''): Json
  33. {
  34. $rs = CompanyGoodModel::alias('a')
  35. ->field('a.id,a.code,a.good_id,b.good_cover_img,b.good_code,b.good_name,b.moq,b.step,b.good_banner_img,b.good_img,b.good_param,b.status,c.inventory,d.unit')
  36. ->leftJoin('good b', 'b.id=a.good_id AND b.is_del=' . CommonModel::$del_normal)
  37. ->leftJoin('inventory_exchange c', 'c.account_id=' . self::$aid . ' AND c.good_id=a.good_id')
  38. ->leftJoin('unit d', 'd.id=b.unit_id AND d.is_del=' . CommonModel::$del_normal)
  39. ->where(['a.is_del' => CommonModel::$del_normal, 'a.code' => $code])
  40. ->withAttr('good_param', function ($val) {
  41. return json_decode($val, true);
  42. })
  43. ->withAttr('good_img', function ($val) {
  44. return explode(',', $val);
  45. })->withAttr('good_banner_img', function ($val) {
  46. return explode(',', $val);
  47. })
  48. ->findOrEmpty()
  49. ->toArray();
  50. return json_show(CommonModel::$success, '获取兑换商品详情成功', $rs);
  51. }
  52. }