ShopGoods.php 9.8 KB

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