12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace app\mobile\logic;
- use app\model\CommonModel;
- use app\model\CompanyGoodModel;
- use app\model\GoodModel;
- use app\model\InventoryExchangeModel;
- use app\model\InventoryShoppingModel;
- use think\response\Json;
- class GoodLogic extends BaseLogic
- {
- //商品列表
- public static function goodList(array $data = []): Json
- {
- $db = CompanyGoodModel::alias('a')
- ->leftJoin('good b', 'b.id=a.good_id AND b.is_del=' . CommonModel::$del_normal)
- ->where(['a.is_del' => CommonModel::$del_normal, 'a.group_id' => self::$group_id]);
- $count = $db->count('a.id');
- $list = $db
- ->field('a.id,a.code,a.good_id,b.good_cover_img,b.good_name,b.moq,b.step,b.price,b.type,0 inventory')
- ->page($data['page'], $data['size'])
- ->order(['a.is_top' => 'desc', 'a.weight' => 'desc', 'a.id' => 'desc'])
- ->withAttr('inventory', function ($val, $da) {
- if ($da['type'] == GoodModel::$type_exchange) return InventoryExchangeModel::where(['account_id' => self::$aid, 'good_id' => $da['good_id']])->value('inventory');
- else return InventoryShoppingModel::where(['good_id' => $da['good_id']])->value('inventory');
- })
- ->select()
- ->toArray();
- return json_show(CommonModel::$success, '获取商品列表成功', ['count' => $count, 'list' => $list]);
- }
- //商品详情
- public static function goodInfo(string $code = ''): Json
- {
- $rs = CompanyGoodModel::alias('a')
- ->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, 0 inventory,d.unit,b.price,b.type')
- ->leftJoin('good b', 'b.id=a.good_id AND b.is_del=' . CommonModel::$del_normal)
- // ->leftJoin('inventory_shopping c', 'c.good_id=a.good_id')
- ->leftJoin('unit d', 'd.id=b.unit_id AND d.is_del=' . CommonModel::$del_normal)
- ->where(['a.is_del' => CommonModel::$del_normal, 'a.code' => $code])
- ->withAttr('good_param', function ($val) {
- return json_decode($val, true);
- })
- ->withAttr('good_img', function ($val) {
- return explode(',', $val);
- })->withAttr('good_banner_img', function ($val) {
- return explode(',', $val);
- })->withAttr('inventory', function ($val, $da) {
- if ($da['type'] == GoodModel::$type_exchange) return InventoryExchangeModel::where(['account_id' => self::$aid, 'good_id' => $da['good_id']])->value('inventory');
- else return InventoryShoppingModel::where(['good_id' => $da['good_id']])->value('inventory');
- })
- ->findOrEmpty()
- ->toArray();
- return json_show(CommonModel::$success, '获取商品详情成功', $rs);
- }
- }
|