12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace Code\Lib;
- use Dever;
- class Core
- {
- public function createCode($product, $cate_id, $product_id, $type = 1, $num = 1)
- {
- if ($product_id > 0) {
- Dever::setInput('set_product_id', $product_id);
- }
-
- //$data['product'] = $product;
- $data['cate_id'] = $cate_id;
- $data['product_id'] = $product_id;
-
- $data['type'] = $type;
- $db = Dever::db('code/info');
- if ($product_id > 0) {
- $code = $db->insert($data, $num);
- $code = $this->view($code, true);
- return $code;
- } else {
- for ($i = 0; $i < $num; $i++) {
- $data['i'] = $i;
- $id = $db->insert($data);
- if ($id) {
- $code = $this->view($id, false);
- $db->update(array('code' => $code, 'where_id' => $id));
- }
- }
- return $code;
- }
- }
- public function view($id, $state)
- {
- if ($state) {
- $code = Dever::uid($id * 10000000);
- $code = 'M' . $code;
- } else {
- $code = Dever::rand(4);
- $code = 'T' . $code . $id;
- }
-
- return $code;
- }
- }
|