ShopGoods.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <?php
  2. namespace common\models;
  3. /**
  4. * This is the model class for table "{{%SHOP_GOODS}}".
  5. *
  6. * @property string $ID
  7. * @property string $GOODS_NAME 商品名称
  8. * @property string $CATE_ID 所属分类ID
  9. * @property string $TYPE 商品来源
  10. * @property string $GIFT_TYPE 商品类型
  11. * @property string $CATEGORY_TYPE 商品分类
  12. * @property string $SELL_TYPE 允许购买方式
  13. * @property int $GOODS_NO 商品编号
  14. * @property string $UNIT 单位
  15. * @property string $COVER 商品封面
  16. * @property int $IMAGES 商品图片
  17. * @property string $CONTENT 商品内容
  18. * @property string $SELL_PRICE_STANDARD 标准价格
  19. * @property int $PRICE_PV 价格PV
  20. * @property int $POINT 兑换积分
  21. * @property int $STORE_NUMS 库存
  22. * @property int $IS_DEL 是否删除
  23. * @property int $CREATED_AT 创建时间
  24. * @property int $UPDATED_AT 更新时间
  25. * @property int $DELETED_AT 删除时间
  26. * @property int $STATUS 状态
  27. * @property string $SORT 排序
  28. */
  29. class ShopGoods extends \common\components\ActiveRecord
  30. {
  31. const SALE_TYPE = [
  32. 1 => [
  33. 'id' => 1,
  34. 'name' => 'Account Balance', //余额购买
  35. 'label' => 'cash',
  36. 'language' => 'shopListAccountBalance',
  37. ],
  38. // 2 => [
  39. // 'id' => 2,
  40. // 'name' => '复消兑换',
  41. // ],
  42. // 3 => [
  43. // 'id' => 3,
  44. // 'name' => '兑换点数',
  45. // 'label' => 'exchange',
  46. // ],
  47. 4 => [
  48. 'id' => 4,
  49. 'name' => 'Travel Bonus',
  50. 'label' => 'tourism_points',
  51. 'language' => 'shopListPayTravelBonus',
  52. ],
  53. 5 => [
  54. 'id' => 5,
  55. 'name' => 'Car Fund',
  56. 'label' => 'garage_points',
  57. 'language' => 'shopListPayCarFund',
  58. ],
  59. 6 => [
  60. 'id' => 6,
  61. 'name' => 'Villa Fund',
  62. 'label' => 'villa_points',
  63. 'language' => 'shopListPayVillaFund',
  64. ],
  65. 7 => [
  66. 'id' => 7,
  67. 'name' => 'PayStack',
  68. 'label' => 'pay_stack',
  69. 'language' => 'saleTypePayStack',
  70. ],
  71. 8 => [
  72. 'id' => 6,
  73. 'name' => 'User Performance',
  74. 'label' => 'prp',
  75. 'language' => 'shopPayTypeUserPerformance',
  76. ],
  77. ];
  78. const GOODS_TYPE = [
  79. 1 =>[
  80. 'name'=>'国内商品',//国内商品
  81. 'discount'=>'50',
  82. 'language' => 'shopGoodTypeDomestic',
  83. ],
  84. 2 =>[
  85. 'name'=>'进口商品',//进口商品
  86. 'discount'=>'60',
  87. 'language' => 'shopGoodTypeImport',
  88. ],
  89. ];
  90. const GIFT_TYPE = [
  91. 1 =>[
  92. 'name'=>'1st Purchase',//报单区
  93. ],
  94. 2 =>[
  95. 'name'=>'Repeat Purchase',//复消区
  96. ],
  97. // 3 =>[
  98. // 'name'=>'Office Entry area',//工作室报单
  99. // ],
  100. // 4 =>[
  101. // 'name'=>'Office Reselling area',//工作室复消
  102. // ],
  103. ];
  104. const STATUS_NAME = [
  105. 1 => 'On sale',//已上架
  106. 0 => 'Sold out',//已下架
  107. ];
  108. const CATEGORY_TYPE = [
  109. [
  110. 'id' => 1,
  111. 'name' => 'Standard Products',//普通商品
  112. 'sell_type' => [
  113. self::SALE_TYPE[1],
  114. self::SALE_TYPE[8],
  115. self::SALE_TYPE[7],
  116. ]
  117. ],
  118. // [
  119. // 'id' => 4,
  120. // 'name' => 'Travel bonus products',//旅游积分商品
  121. // 'sell_type' => [
  122. // self::SALE_TYPE[4]
  123. // ]
  124. // ],
  125. // [
  126. // 'id' => 5,
  127. // 'name' => 'Car Fund Products',
  128. // 'sell_type' => [
  129. // self::SALE_TYPE[5]
  130. // ]
  131. // ],
  132. // [
  133. // 'id' => 6,
  134. // 'name' => 'Villa Fund Products',
  135. // 'sell_type' => [
  136. // self::SALE_TYPE[6]
  137. // ]
  138. // ],
  139. ];
  140. /**
  141. * @inheritdoc
  142. */
  143. public static function tableName()
  144. {
  145. return '{{%SHOP_GOODS}}';
  146. }
  147. /**
  148. * @inheritdoc
  149. */
  150. public function rules()
  151. {
  152. return [
  153. [['SELL_DISCOUNT','GOODS_NAME', 'CATE_ID','GIFT_TYPE', 'GOODS_NO', 'PRICE_PV','STORE_NUMS', 'SELL_TYPE', 'CATEGORY_TYPE', 'SELL_PRICE_STANDARD'], 'required'],
  154. [['STORE_NUMS'], 'integer'],
  155. [['PRICE_PV','POINT', 'CATEGORY_TYPE' ,'SELL_PRICE_STANDARD'], 'number'],
  156. [['ID','CATE_ID', 'GOODS_NO','GIFT_TYPE'], 'string', 'max' => 32],
  157. [['UNIT'], 'string', 'max' => 16],
  158. [['COVER', 'GOODS_NAME'], 'string', 'max' => 255],
  159. [['IMAGES','CONTENT'], 'string', 'max' => 4000],
  160. [['GOODS_NAME'], 'unique'],
  161. [['ID'], 'unique'],
  162. ];
  163. }
  164. /**
  165. * @inheritdoc
  166. */
  167. public function attributeLabels()
  168. {
  169. return [
  170. 'ID' => 'ID',
  171. 'GOODS_NAME' => '商品名称',
  172. 'CATE_ID' => '所属分类ID',
  173. 'SELL_DISCOUNT' => '会员折扣',
  174. 'GIFT_TYPE' => '商品类型',
  175. 'CATEGORY_TYPE' => '商品分类',
  176. 'SELL_TYPE' => '出售方式',
  177. 'GOODS_NO' => '商品编号',
  178. 'UNIT' => '商品单位',
  179. 'COVER' => '商品封面',
  180. 'IMAGES' => '商品图片',
  181. 'CONTENT' => '商品内容',
  182. 'SELL_PRICE_STANDARD' => 'US price($)',
  183. 'PRICE_PV' => '价格PV',
  184. 'STORE_NUMS' => '库存',
  185. 'STATUS' => '是否上架',
  186. 'IS_DEL' => '是否删除',
  187. 'CREATED_AT' => '创建时间',
  188. 'UPDATED_AT' => '更新时间',
  189. 'DELETED_AT' => '更新时间',
  190. 'SORT' => '排序',
  191. ];
  192. }
  193. /**
  194. * 判断提现状态
  195. * @param $nowStatus
  196. * @param $toStatus
  197. * @return string
  198. */
  199. public static function chkAuditStatus($nowStatus, $toStatus) {
  200. $statusName = self::STATUS_NAME;
  201. // $msg = 'The current product status is【' . $statusName[$nowStatus] . '】,cannot be set to【' . $statusName[$toStatus] . '】';// 当前商品状态为 无法设置为
  202. $msg = \Yii::t('ctx', 'shopSetProductStatusErrorNotice', [
  203. 'nowStatus' => $statusName[$nowStatus],
  204. 'newStatus' => $statusName[$toStatus]
  205. ]);
  206. switch ($toStatus) {
  207. // 下架
  208. case 0:
  209. if ($nowStatus == 1) {
  210. $msg = '';
  211. }
  212. break;
  213. //上架
  214. case 1:
  215. if ($nowStatus == 0) {
  216. $msg = '';
  217. }
  218. break;
  219. default:
  220. }
  221. return $msg;
  222. }
  223. /**
  224. * 支付方式
  225. * @return array
  226. */
  227. public static function payTypes(){
  228. return [
  229. 'cash'=>[
  230. 'name'=> \Yii::t('ctx', 'shopPayTypeCash')//余额支付
  231. ],
  232. 'prp' => [
  233. 'name' => \Yii::t('ctx', 'shopPayTypeUserPerformance')
  234. ],
  235. 'pay_stack' => [
  236. 'name' => 'PayStack'
  237. ],
  238. ];
  239. }
  240. // 获取商品类型
  241. public static function getGiftType() {
  242. return [
  243. 1 =>[
  244. 'name'=>\Yii::t('ctx', 'shopList1stPurchase'),//报单区
  245. ],
  246. 2 =>[
  247. 'name'=>\Yii::t('ctx', 'shopListRepeatPurchase'),//复消区
  248. ],
  249. // 3 =>[
  250. // 'name'=>\Yii::t('ctx', 'shopListEntryArea'),//工作室报单
  251. // ],
  252. // 4 =>[
  253. // 'name'=>\Yii::t('ctx', 'shopListResellingArea'),//工作室复消
  254. // ],
  255. ];
  256. }
  257. // 获取分类类型
  258. public static function getCategoryType() {
  259. return [
  260. [
  261. 'id' => 1,
  262. 'name' => \Yii::t('ctx', 'shopListStandardProducts'),//普通商品
  263. 'sell_type' => [
  264. self::SALE_TYPE[1],
  265. self::SALE_TYPE[8],
  266. self::SALE_TYPE[7],
  267. ]
  268. ],
  269. ];
  270. }
  271. public static function getSaleType(): array
  272. {
  273. return array_map(function ($item) {
  274. $item['name'] = \Yii::t('ctx', $item['language']);
  275. return $item;
  276. }, self::SALE_TYPE);
  277. }
  278. public static function getGoodType(): array
  279. {
  280. return array_map(function ($item) {
  281. $item['name'] = \Yii::t('ctx', $item['language']);
  282. return $item;
  283. }, self::GOODS_TYPE);
  284. }
  285. }